#include <iostream>
#include <future>
#include "../../../../../../../usr/include/c++/11/bits/this_thread_sleep.h"

int Add(int n1,int n2)
{
    std::cout<<"Add"<<std::endl;
    return n1+n2;
}

int main()
{
    //async模板函数 内部创建线程去调用函数
    //std::launch::async 异步策略  直接去调用函数
    std::future<int> res = std::async(std::launch::async,Add,11,22);

    //std::launch::deferred 同步策略  等到调用res.get() 时再去调用对象
    std::future<int> res1 = std::async(std::launch::deferred,Add,11,22);

    std::this_thread::sleep_for(std::chrono::seconds(1));

    std::cout<<"-----------------------------------"<<std::endl;

    std::cout<<res.get()<<std::endl;

    std::cout<<res1.get()<<std::endl;

    return 0;
}